<template>
  <el-form ref="ruleForm"
           :model="ruleForm"
           :rules="rules"
           label-width="100px"
           class="demo-ruleForm">
    <el-form-item label="关闭原因"
                  prop="desc">
      <el-input v-model="ruleForm.reason"
                type="textarea"></el-input>
    </el-form-item>
    <el-form-item>
      <el-button type="primary"
                 @click="submitForm('ruleForm')">确定</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import { quotation } from '@service'
export default {
  name: 'QuotationSendClosed',
  props: {
    templateId: {
      type: String,
      default: ''
    }
  },
  data () {
    return {
      ruleForm: {},
      rules: {
        reason: [
          { required: true, message: '请输入关闭原因', trigger: 'blur' }
        ]
      }
    }
  },
  created () {
    console.log('templateId+++++', this.templateId)
  },
  methods: {
    submitForm (formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.closeSubmit()
          alert('submit!');
        } else {
          return false;
        }
      });
    },
    async closeSubmit () {
      const params = {
        ...this.ruleForm.reason,
        templateId: this.templateId
      }
      const response = await quotation.contractClose(params)
      if (response?.data?.code === 0) {
        this.$message({
          message: '操作成功',
          type: 'success'
        });
      }
    }
  }
}
</script>

<style>
</style>